{include file="admin/common/header" /}
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <table id="admin_table" lay-filter="admin_table"></table>
    </div>
</div>
<script type="text/html" id="add_toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md {php}if(!check_auth(__url('/app/book/admin/book/add'))){ echo 'layui-hide';} {/php}"
            data-open="/app/book/admin/book/add"
            data-title="添加知识库" data-reload="2">
        <i class="layui-icon layui-icon-add-1"></i>
        新增知识库
    </button>
</script>

<script type="text/html" id="thumbTpl">
    {{#  if(d.thumb){ }}
    <img id="thumb_{{d.id}}" src="{{d.thumb}}" alt="" width="35" onmouseover="hui_img_preview('thumb_{{d.id}}','{{d.thumb}}')"
         onmouseout="layer.closeAll();">
    {{#  } }}
</script>

<script type="text/html" id="barDemo">
    <button class="pear-btn pear-btn-primary pear-btn-xs" title="编辑"
            data-open="/app/book/admin/book/edit?id={{d.id}}"
            data-title="编辑" data-reload="2">
        编辑
    </button>
    <button class="pear-btn pear-btn-zise pear-btn-xs" title="详情" data-title="详情-{{d.title}}"
            data-open-addTab="/app/book/admin/doc/index?book_id={{d.id}}" data-open-id="book_doc_id_{{d.id}}">
        详情
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-xs" title="删除"
            data-delete="/app/book/admin/book/delete?id={{d.id}}"
            data-title="您确定要删除吗？" data-reload="2">
        删除
    </button>
</script>
{include file="admin/common/footer" /}
<script>
  layui.use(['table', 'jquery'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    table.render({
      elem: '#admin_table'
      , toolbar: '#add_toolbar'
      , defaultToolbar: [{
        layEvent: 'refresh',
        icon: 'layui-icon-refresh',
        title: '刷新'
      }, 'filter']
      , method: 'get'
      , url: "/app/book/admin/book/index"
      , parseData: function (res) {
        return {
          "code": res.code,
          "msg": res.msg,
          "count": res.count,
          "data": res.data
        };
      }
      , cellMinWidth: 100
      , cols: [[
        {field: 'id', title: 'ID', align: 'center', width: 80}
        , {field: 'sort', title: '排序', align: 'center', width: 80}
        , {field: 'thumb', title: '缩略图', width: 50, templet: '#thumbTpl', align: 'center'}
        , {field: 'title', title: '标题'}
        , {field: 'count', title: '文档数', align: 'center', width: 80}
        , {
          field: 'is_index', title: '首页展示', width: 80, align: 'center', templet: function (d) {
            if (d.is_index === 1) {
              return '<span class="layui-badge layui-bg-blue">是</span>';
            } else {
              return '<span class="layui-badge layui-bg-orange">否</span>';
            }
          }
        }
        , {
          field: 'status', title: '状态', width: 80, align: 'center', templet: function (d) {
            if (d.status === 1) {
              return '<span class="layui-badge layui-bg-blue">启用</span>';
            } else {
              return '<span class="layui-badge layui-bg-orange">禁用</span>';
            }
          }
        }
        , {
          fixed: 'right', title: '操作', toolbar: '#barDemo', width: 230, align: 'center'
        }
      ]]
      ,
      id: 'testReload'
      , page: false
    });

    table.on('toolbar(admin_table)', function (obj) {
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });

  });
</script>
</body>
</html>
